package f3f5.mishacord;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class MishaThread extends Thread {
    private final Socket mishaSocketIn;
    private final Socket mishaSocketOut;
    private final InputStream mishaInput;
    private final OutputStream mishaOutput;
    private final MishaThread.Type type;

    public MishaThread(Socket mishaSocketIn, Socket mishaSocketOut, MishaThread.Type type) throws IOException {
        this.mishaSocketIn = mishaSocketIn;
        this.mishaSocketOut = mishaSocketOut;
        this.mishaInput = mishaSocketIn.getInputStream();
        this.mishaOutput = mishaSocketOut.getOutputStream();
        this.type = type;
    }

    public void run() {
        try {
            int i;
            try {
                while(this.mishaSocketIn.isConnected() && this.mishaSocketOut.isConnected() && (i = this.mishaInput.read()) != -1) {
                    this.mishaOutput.write(i);
                    this.mishaOutput.flush();
                }
            } catch (IOException var10) {
            }
        } finally {
            if (this.type == MishaThread.Type.C2S) {
                System.out.println("МИША КЛИЕНТ (" + this.mishaSocketIn.getInetAddress() + ") ХАЗ ДИСКОННЕКТЕД");
            }

            try {
                this.mishaSocketOut.close();
            } catch (Exception var9) {
                System.out.println("ЕРРОР ВХАЙЛ КЛОЗИНГ МИША СОКЕТ: " + var9.getMessage());
            }
        }
    }

    public static enum Type {
        C2S,
        S2C;
    }
}
